home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / (A)TB / (A)TBP.ADF / Diary / diary.c < prev    next >
C/C++ Source or Header  |  1991-06-20  |  2KB  |  55 lines

  1. #include <stdio.h>
  2. #include <time.h>
  3.  
  4. main(argc,argv)
  5. int argc;
  6. char *argv[];
  7. {
  8.    FILE *stream,*fopen();
  9.    char FileName[50],
  10.         Month[4],
  11.         Day[3],
  12.         Year[3];
  13.    char WriteLine[40][80],*TheTime;
  14.    time_t curtime;
  15.    unsigned int numlines,i;
  16.    if(argc < 2) {
  17.       printf("Usage: Diary <directory>\n\nWhere directory is where to put the output of the diary program.\nIT MUST END IN : OR /!! EXAMPLE: DH0:DIARY/\nYou can put this in a batch file or alias to make it easier (Example):\nDIARY DH0:DIARY/\n"
  18.              "\nThere will be a different file for each day, but you can add on to it\nas much as you want during the day.\n");
  19.       exit(5);
  20.    }
  21.    time(&curtime);
  22.    TheTime=ctime(&curtime);
  23.    for(i=0;i<3;i++)
  24.       Month[i]=toupper(TheTime[i+4]);
  25.    Month[3]='\0';
  26.    for(i=0;i<2;i++)
  27.       Day[i]=TheTime[i+8];
  28.    Day[2]='\0';
  29.    for(i=0;i<2;i++)
  30.       Year[i]=TheTime[i+22];
  31.    Year[2]='\0';
  32.    sprintf(FileName,"%s%s-%s-%s\0",argv[1],Day,Month,Year);
  33.    printf("HDiary v1.0: Written by Captain Spock of Starship BBS (702) 361-2725\n\nFile = %s:\nType 'X' on a blank line to end input.\n======================================\n\n",FileName);
  34.    printf("%s---------------------------------------------------------------------------\n",TheTime);
  35.    for(;;) {
  36.       gets(WriteLine[numlines]);
  37.       if(toupper(WriteLine[numlines][0]) == 'X') break;
  38.       ++numlines;
  39.    }
  40.    if(numlines==0) {
  41.       printf("Aborted..\n");
  42.       exit(10);
  43.    }
  44.    if(!(stream=fopen(FileName,"a"))) {
  45.       printf("Couldn't open diary file: %s\n",FileName);
  46.       exit(5);
  47.    }
  48.    fprintf(stream,"%s---------------------------------------------------------------------------\n",TheTime);
  49.    for(i=0;i<numlines;i++)
  50.       fprintf(stream,"%s\n\0",WriteLine[i]);
  51.    fputc('\n',stream);
  52.    fclose(stream);
  53.    printf("Saved..\n");
  54. }
  55.